package com.hs.srm.admin.modules.orders.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hs.srm.admin.modules.orders.dao.StockDao;
import com.hs.srm.admin.modules.orders.entity.StockEntity;
import com.hs.srm.admin.modules.orders.service.StockService;
import com.hs.srm.admin.modules.orders.vo.StockItemVO;
import com.hs.srm.base.common.utils.QueryParam;
import com.hs.srm.common.utils.PageUtils;

/**
 * 采购订单行项目Service实现
 * 
 * @author Sunnykid
 *
 * @date 2019年3月17日
 */
@Service("stockService")
public class StockServiceImpl extends ServiceImpl<StockDao, StockEntity> implements StockService {

	@Override
	public PageUtils selectDetailPage(Map<String, Object> params) {
		Page<StockEntity> page = this.selectDetailPage(new QueryParam<StockEntity>(params).getPage(),
				new EntityWrapper<StockEntity>(), params);
		return new PageUtils(page);
	}

	private Page<StockEntity> selectDetailPage(Page<StockEntity> page, Wrapper<StockEntity> wrapper,
			Map<String, Object> params) {
		page.setRecords(this.baseMapper.selectDetailPage(page, wrapper, params));
		return page;
	}

	/**
	 * 
	 * 批量查询发货的数据
	 */
	@Override
	public List<StockEntity> findById(List<String> idList) {
		return this.baseMapper.findByPoItemIds(idList);
	}

	@Override
	public boolean insertStock(StockEntity stockEntity) {
		boolean isSuccess = this.insert(stockEntity);
		return isSuccess;
	}

	@Override
	public List<StockEntity> selectStockByFph(String deliverNo) {
		EntityWrapper<StockEntity> queryWrapper = new EntityWrapper<StockEntity>();
		queryWrapper.eq("deliver_no", deliverNo);
		List<StockEntity> list = this.selectList(queryWrapper);
		return list;
	}

	/**
	 *更新发货数据
	 */
	@Override
	public int updaeStock(StockEntity stockEntity) {
		return this.baseMapper.updaeStock(stockEntity);
	}

	@Override
	public List<StockEntity> selectStockByDdh(String PoNo) {
		return this.baseMapper.selectStockByDdh(PoNo);
	}

	@Override
	public StockEntity selectStockByPo(String poNo, String itemNo) {
		EntityWrapper<StockEntity> queryWrapper = new EntityWrapper<StockEntity>();
		queryWrapper.eq("po_no", poNo);
		queryWrapper.eq("item_no", itemNo);
		StockEntity stockEntity = this.selectOne(queryWrapper);
		return stockEntity;
	}

	@Override
	public PageUtils listStockItem(Map<String, Object> params) {
		Page<StockItemVO> page = new QueryParam<StockItemVO>(params).getPage();
		List<StockItemVO> list = this.baseMapper.listStockItem(page, new EntityWrapper<StockItemVO>(), params);
		return new PageUtils(page.setRecords(list));
	}

}
